<html>
<head><meta charset="utf-8"><title>removing a line in a suggestion · t-compiler/wg-diagnostics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/index.html">t-compiler/wg-diagnostics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html">removing a line in a suggestion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="157040000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040000">(Jan 28 2019 at 17:03)</a>:</h4>
<p>Am I right in thinking that there's no way to remove a line in a suggestion?<br>
cc <span class="user-mention" data-user-id="119031">@Esteban Küber</span></p>



<a name="157040230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040230">(Jan 28 2019 at 17:06)</a>:</h4>
<p>You need a span that goes from the beginning on the line to be removed to the beginning of the next one, replacing with empty string</p>



<a name="157040264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040264">(Jan 28 2019 at 17:06)</a>:</h4>
<p>I thought that might work, but I was struggling at a glance to figure out how to get that with the APIs on <code>SourceMap</code>?</p>



<a name="157040266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040266">(Jan 28 2019 at 17:06)</a>:</h4>
<p>That will do what you want but might get you in tricky span offset calculation waters</p>



<a name="157040286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040286">(Jan 28 2019 at 17:07)</a>:</h4>
<p>What span do you available?</p>



<a name="157040291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040291">(Jan 28 2019 at 17:07)</a>:</h4>
<p>*have</p>



<a name="157040313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040313">(Jan 28 2019 at 17:07)</a>:</h4>
<p>I'm looking at <a href="https://github.com/rust-lang/rust/issues/52891" target="_blank" title="https://github.com/rust-lang/rust/issues/52891">#52891</a>. I've got the span for <code>issue_52891::a</code> in <code>use issue_52891::a;</code>.</p>



<a name="157040380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040380">(Jan 28 2019 at 17:08)</a>:</h4>
<p>I noticed that if I got a <code>SourceFile</code> for the <code>Span</code> then I could call <code>line_begin_pos</code>.</p>



<a name="157040418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040418">(Jan 28 2019 at 17:09)</a>:</h4>
<p>And I could get one of those from <code>lookup_byte_offset</code> using either of <code>.hi()</code> or <code>.lo()</code>.</p>



<a name="157040437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040437">(Jan 28 2019 at 17:09)</a>:</h4>
<p>Yep that's what I'd do</p>



<a name="157040449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040449">(Jan 28 2019 at 17:09)</a>:</h4>
<p>There's a method to consume backwards until a certain condition is true</p>



<a name="157040498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040498">(Jan 28 2019 at 17:10)</a>:</h4>
<p>Passed in as q closure</p>



<a name="157040517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040517">(Jan 28 2019 at 17:10)</a>:</h4>
<p>I think it's used to get the <code>pub</code> span somewhere</p>



<a name="157040520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040520">(Jan 28 2019 at 17:10)</a>:</h4>
<p>It's a hack</p>



<a name="157040523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040523">(Jan 28 2019 at 17:10)</a>:</h4>
<p>But it works <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="157040528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040528">(Jan 28 2019 at 17:10)</a>:</h4>
<p>I figured I'd be able to do something like that if it went forwards by looking for <code>\n</code>.</p>



<a name="157040536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040536">(Jan 28 2019 at 17:10)</a>:</h4>
<p>or <code>EOF</code> I guess.</p>



<a name="157040674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157040674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157040674">(Jan 28 2019 at 17:12)</a>:</h4>
<p>Or maybe I could take one <code>BytePos</code> away from the <code>line_begin_pos</code> of the next line. Might be a straight forward variation on <a href="https://doc.rust-lang.org/nightly/nightly-rustc/src/syntax_pos/lib.rs.html#1074-1077" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/src/syntax_pos/lib.rs.html#1074-1077">the <code>line_begin_pos</code> function</a> but that may not work for reasons I'm not aware of.</p>



<a name="157041437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041437">(Jan 28 2019 at 17:24)</a>:</h4>
<p>If you try to remove from here to next <code>\n</code>, the things to account for are multiline strings (they are evil) and <code>Eof</code></p>



<a name="157041468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041468">(Jan 28 2019 at 17:24)</a>:</h4>
<p>also one could write</p>
<div class="codehilite"><pre><span></span>use
foo::bar:Baz
as
Qux
;
</pre></div>


<p>and you should be able to account for that :-/</p>



<a name="157041510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041510">(Jan 28 2019 at 17:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116107">@davidtwco</span> ^</p>



<a name="157041599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041599">(Jan 28 2019 at 17:26)</a>:</h4>
<p>I expected that would be the <code>Span</code> of the <code>Item</code> that represents the use statement - but I've not been able to find a way to get at that from where this error is reported.</p>



<a name="157041650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041650">(Jan 28 2019 at 17:27)</a>:</h4>
<p>I think that the <code>Qux</code> in the example above is a Spanned Ident, so if present you should use that for the tentative end of it</p>



<a name="157041662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041662">(Jan 28 2019 at 17:27)</a>:</h4>
<p>Also, I know there were prior PRs dealing with this were the <code>;</code> was sometimes included and sometimes not</p>



<a name="157041664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041664">(Jan 28 2019 at 17:27)</a>:</h4>
<p>I think that (having an <code>Item</code>) would be necessary as well to distinguish between <code>use foo:{a, b};</code> and <code>use foo::a;</code></p>



<a name="157041717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041717">(Jan 28 2019 at 17:28)</a>:</h4>
<p>yep</p>



<a name="157041720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041720">(Jan 28 2019 at 17:28)</a>:</h4>
<p>So I know what <code>Span</code> to suggest - the line (or multiple lines) or just the <code>binding_span</code> I have.</p>



<a name="157041733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041733">(Jan 28 2019 at 17:28)</a>:</h4>
<p>Makes sense</p>



<a name="157041753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/removing%20a%20line%20in%20a%20suggestion/near/157041753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/removing.20a.20line.20in.20a.20suggestion.html#157041753">(Jan 28 2019 at 17:29)</a>:</h4>
<p>I've not been able to find an example in that file of getting an <code>Item</code> from a <code>NodeId</code> - the <code>Resolver</code> doesn't really need to do that.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>